package ui;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.WindowOwner;


import dominio.Mejora;
import dominio.Planta;
import dominio.Zombie;

import applicationModels.AlmanaqueZombies;
import applicationModels.Juego;
import applicationModels.Mejorar;

public class AlmanaqueWindow extends SimpleWindow<AlmanaqueZombies>{
    private static final long serialVersionUID = 1L;
	
	public AlmanaqueWindow(WindowOwner parent) {
		super(parent, new AlmanaqueZombies());
	}
	
	@Override
	protected void addActions(Panel actionsPanel) {
		
		new Button(actionsPanel)
		.setCaption("Cerrar")
		.onClick(new MessageSend(this, "close"));
		
		new Button(actionsPanel)
		.setCaption("Buscar")
		.onClick(new MessageSend(this.getModelObject(), "search"))
		.setAsDefault()
		.disableOnError();
		
		
		
		
	}
	
	@Override
	protected void createFormPanel(Panel mainPanel) {
		
		
		
		//mainPanel.setLayout(new HorizontalLayout());
		
		new Label(mainPanel).setText("Aqui puedes ver los datos de cada Zombie");
		
		Panel principal = new Panel(mainPanel).setLayout(new HorizontalLayout());
		
		
		this.elPanelDeLosZombies(principal);
		this.makeZombiesDescription(principal);
		
	}
	
	public void elPanelDeLosZombies(Panel mainPanel){
		Panel laTabla = new Panel(mainPanel);
		
		laTabla.setLayout(new VerticalLayout());
		
		this.makeZombiesPanel(laTabla);
		
		
		
	}
	

	
	public void makeZombiesDescription(Panel mainPanel){
		Panel datosZombie = new Panel(mainPanel).setLayout(new VerticalLayout());
		Panel nombre = new Panel(datosZombie).setLayout(new HorizontalLayout());
		Label nombreZombie = new Label(nombre).setText("Nombre: ");
		Label nombreZombiebind = new Label(nombre);
		nombreZombiebind.bindValueToProperty("nombreZombieSelec");
		nombreZombiebind.setFontSize(14);
		nombreZombiebind.setHeigth(30);
		nombreZombiebind.setWidth(150);
		
		
		Panel ataque = new Panel(datosZombie).setLayout(new HorizontalLayout());
		Label ataqueLabel = new Label(ataque).setText("Ataque: ");
		Label ataqueZombie = new Label(ataque);
		ataqueZombie.bindValueToProperty("puntosAtaZ");
		ataqueZombie.setHeigth(20);
		ataqueZombie.setWidth(50);
		
		Panel def = new Panel(datosZombie).setLayout(new HorizontalLayout());
		Label defLabel = new Label(def).setText("Defensa: ");
		Label defZombie = new Label(def);
		defZombie.bindValueToProperty("puntosDefZ");
		defZombie.setHeigth(20);
		defZombie.setWidth(50);
		
		
	}
	
	// *************************************************************************
	// ** TABLA CON LOS ZOMBIES
	// *************************************************************************
	
	public void makeZombiesPanel(Panel mainPanel) {
		Panel zombies = new Panel(mainPanel);
		zombies.setLayout(new VerticalLayout());
		//Panel botones = new Panel(mainPanel).setLayout(new VerticalLayout());
		
		new Label(zombies).setText("Ingrese el Zombie a buscar");
		new TextBox(zombies).bindValueToProperty("zombieABuscar");
		
		this.createZombiesGrid(zombies);
		//this.addActions(botones);
	}
	
	protected void createZombiesGrid(Panel mainPanel) {
		
		Table<Zombie> table = new Table<Zombie>(mainPanel, Zombie.class);
		table.setHeigth(200);
		table.setWidth(450);
		table.bindItemsToProperty("resultado");
		table.bindValueToProperty("zombieSeleccionado");

		this.describeZombiesGrid(table);
		
		
	}
	
	/**
	 * Crea tres columnas para la tabla de zombies
	 *  
	 * @param table
	 */
	protected void describeZombiesGrid(Table<Zombie> table) {
		new Column<Zombie>(table) //
			.setTitle("Nombre")
			//.setFixedSize(150)
			.bindContentsToProperty("nombre");
/*
		new Column<Zombie>(table) //
			.setTitle("Mejora Ataque")
			//.setFixedSize(150)
			.bindContentsToProperty("puntosAtaque");
		
		new Column<Zombie>(table) //
			.setTitle("Mejora Defensa")
		//	.setFixedSize(150)
			.bindContentsToProperty("puntosDefensa");
			*/
	}
	
}
